<template>
  <div class="book-detail">
    <div class="book-item">
      <img v-lazy="book.cover"/>
      <div class="content">
        <div class="title">{{book.name}}</div>
        <div class="author">{{book.author}}</div>
        <div class="status">{{!!book.read_chapter_count ? `已读${book.read_chapter_count}章` : '还未开始阅读'}}</div>
        <!-- <div class="status">用户身份</div> -->
      </div>
    </div>
    <section class="section" v-for="capter in capters" :key="capter.id">
      <router-link tag="div" :to="{path:'/chapter',query:{id:capter.id}}">{{capter.title}}</router-link>
    </section>
    <ul class="tab-bar">
      <router-link class="find" tag="li" v-if="!book.read_chapter_count || (!!book.read_chapter_count && !!capters[book.chapter_index])" :to="{path:'/chapter',query:{id:!!book.read_chapter_count ? capters[book.chapter_index].id :capters[0].id}}">
        <span>{{!!book.read_chapter_count ? '继续阅读' : '开始阅读'}}</span>
      </router-link>
      <li class="find" v-else>
        <span>已完成阅读</span>
      </li>
    </ul>
    <i class="icon-back" @click.stop="goBack"/>
  </div>
</template>

<script>
import { mapGetters } from "vuex";

export default {
  components: {},
  data() {
    return {
      book: {},
      capters: [{ id: "" }] //避免初始化时报错，这里写入一个默认值
    };
  },
  props: {},
  watch: {},
  methods: {
    goBack() {
      this.$router.back();
    }
  },
  filters: {},
  computed: {
    ...mapGetters(["userID"])
  },
  created() {
    document.title = "书籍详情";
  },
  mounted() {
    this.$$api_book_findMyArticle({
      data: this.$router.currentRoute.query.id,
      fn: res => {
        this.book = res;
        this.$$api_book_chapterList({
          data: this.book.book_id,
          fn: res => {
            this.capters = res;
          }
        });
      }
    });
  },
  destroyed() {
    document.title = "课外读物";
  }
};
</script>

<style lang="scss" scoped>
@import "~@/assets/scss/const.scss";
@import "~@/assets/scss/mixin.scss";

.book-detail {
  background: $app-background-color;
  padding-bottom: 50px;
  .book-item {
    background: $app-background-color;
    display: flex;
    flex-direction: row;
    flex-wrap: nowrap;
    margin: 20px;
    margin-bottom: 10px;
    width: 90%;
    overflow: hidden;
    justify-content: center;
    align-items: center;
    img {
      display: block;
      width: 90px;
      min-width: 90px;
      height: 120px;
      margin-right: 10px;
      background: #e9e9e9;
    }
    .content {
      flex: 1;
      line-height: 20px;
      font-size: 12px;
      color: #999999;
      font-family: PingFang-SC-Medium;
      line-height: 22px;
      min-width: 0;
      .title {
        font-size: 16px;
        color: #1a1a1a;
        height: 44px;
        @include ellipsis(2);
      }
      .price {
        color: #eb4c43;
      }
    }
  }
  .section {
    padding-left: 20px;
    div {
      border-bottom: 1px solid lightgray;
      height: 60px;
      line-height: 60px;
      color: #b3b3b3;
      font-size: 12px;
    }
  }

  .tab-bar {
    @include onepx();
    position: fixed;
    z-index: 100;
    bottom: 0;
    width: 100%;
    height: 50px;
    text-align: center;
    display: flex;
    flex-direction: row;
    background-color: #ffffff;
    // box-shadow: 0px 1px 10px 1px #888;
    li {
      flex: 1;
      // color: #999;
      display: block;
      color: #65acdf;
      line-height: 50px;
      span {
        display: block;
        font-size: 12px;
      }
      &:first-child {
        border-right: 1px solid rgba(7, 17, 27, 0.1);
      }
    }

    li.router-link-active {
      color: #018cfc;
      transform: scale(1.1);
    }
  }
  .icon-back {
    position: fixed;
    top: 10px;
    left: 10px;
    font-size: 40px;
    color: #999999;
  }
}
</style>

